1. Field of the Invention
The present invention relates to encoding processing suited to packetize variable-length encoding data.
2. Description of the Related Art
As compression encoding methods for compressing video and audio data in a digital form, Moving Picture Experts Group (MPEG) methods have been internationally standardized. The MPEG is a group for examining moving-picture encoding methods for storage in a sub committee 29 (SC29) of a Joint Technical Committee 1 (JTC1) in the International Organization for Standardization/International Electrotechnical Commission (ISO/IEC). The MPEG methods include a MPEG-2 method (ISO 13818).
In the MPEG-2 method, transfer formats for encoding video and audio data are specified. They include an elementary stream (ES) indicating compression codes of video and audio data, a packetized elementary stream (PES) indicating packetized ESs, and a transport stream (TS) serving as a format for multiplexing a plurality of PESs.
In the header information of a PES, a 33-bit field called a presentation time stamp (PTS) can be inserted. This time information indicates timing when video and audio data is output after an ES including the video and audio data is decoded in a decoding section. As for video data, this information indicates a time when a picture appearing first after the PTS is received is output.
Only one PTS can be disposed in one PES. Therefore, it is preferred that one PES be formed of at most one picture when ESs are packetized. If one PES is formed of more than one picture, for example, if one PES is formed of two pictures, since only one PTS can be provided, an error may occur in the decoding section.
The header information of a PES includes a 16-bit field called PES—packet— length. This field expresses a value from 0x0001 (1) to 0xffff (65535) (0x indicates a hexadecimal notation), and indicates the length of data stored in the PES. As an exception, a value of 0x0000 (0) is allowed in a video PES to mean that a data length is not specified.
The number of data items in one picture differs according to the type of the picture. An I picture, which is an intra-coded picture, for example, has several times as many data items as in a P picture (forward-direction predictive-coded picture) and a B picture (bidirectionally predictive-coded picture), which are inter-coded pictures. Therefore, the length of data may exceed 0xffff, specified in PES—packet—length. In this case, 0x0000 is specified in PES—packet—length.
In the MPEG-2 method, to generate TSs, PESs are divided into portions each having 182 bytes, which is the maximum number of data items which can be stored in a TS, and the portions are placed in a plurality of TSs. If the last portion does not exactly fit in the last TS, which also has 182 bytes, stuffing bytes are inserted before the last portion to fill the last TS.
Therefore, when 0x0000 is specified in PES—packet—length, the data length of a PES cannot be determined until the next PES is input. Consequently, a PES-header detector for detecting a PES header, a buffer for delaying PES data by 182 bytes at most, and a data-length counter for counting the data length of a PES are required to generate TSs. In addition, processing for inserting stuffing bytes and for placing delayed PES data to generate TSs according to PES-header detection and a data-length count is required.
As described above, when the number of data items in one PES exceeds 0xffff, PES—packet—length in the PES header is set to 0x0000. Therefore, in a subsequent TS generation processing, the data length of the PES cannot be determined. The above-described processing is required for TS generation. It is therefore difficult to make an encoding apparatus compact and an encoding speed fast.